home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / clptick.zip / TICK.C < prev    next >
C/C++ Source or Header  |  1993-04-07  |  2KB  |  77 lines

  1. /*
  2. **    Program..: Tickerc.c
  3. **    Author...: Brenton Farmer
  4. **    Date.....: 10/10/91
  5. **
  6. **    Purpose..: C code to support Clipper ticker functions.
  7. **
  8. **    int  C10ckSet( iTime)
  9. **    void C10ckISR( INTERRUPT_REGS r)
  10. */
  11.  
  12. #include "extend.h"
  13. #include <dos.h>
  14.  
  15. typedef struct {
  16.     unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
  17. } INTERRUPT_REGS;
  18.  
  19. void ( interrupt far *old_int8)();
  20. void interrupt far C10ckISR( INTERRUPT_REGS);
  21.  
  22. extern void ( interrupt far *_getvector( unsigned int))();
  23. extern void _setvector( unsigned int, void( interrupt far *)());
  24. extern char * _getindosAddress();
  25.  
  26. int Ticks = 0;                // Call Clipper routine every Ticks
  27. int TickerCount = 0;        // How many ticks have elapsed
  28. int Busy = 0;                // Flag to prevent Ticker recursion
  29.  
  30. char far *indos = 0;
  31.  
  32. CLIPPER C10ckSet()
  33. {
  34.     int ReturnValue = 0;
  35.     int TickValue = 0;
  36.  
  37.     if ( PCOUNT == 1 && ISNUM(1))
  38.     {
  39.         ReturnValue = 1;
  40.         if ( ( TickValue = _parni( 1)) != 0) // If TickValue != 0 Setup Timer
  41.         {
  42.             Ticks = TickValue;                     // Activate my isr every ( Ticks)
  43.             TickerCount = 0;                         // Time elapsed in ticks
  44.             Busy = 0;                                 // Busy Flag used by my isr
  45.  
  46.             indos = _getindosAddress();         // Get indos address
  47.  
  48.             old_int8 = _getvector( 0x08);         // Get current int 8 isr
  49.             _setvector( 0x08, C10ckISR);         // Set int 8 to my isr
  50.         }
  51.         else
  52.             _setvector( 0x08, old_int8);
  53.     }
  54.     _retl( ReturnValue);
  55. }
  56.  
  57.  
  58. void interrupt far C10ckISR( INTERRUPT_REGS r)
  59. {
  60.     (*old_int8)();                                // Execute old handler
  61.  
  62.     if ( !Busy)                                    // Busy must be 0 (Prevents recursion)
  63.     {
  64.         ++Busy;                                    // Increment Busy flag
  65.         if ( ++TickerCount >= Ticks)        // Has the appropriate time passed
  66.         {
  67.             _intenable();                        // Re-Enable Interrupts
  68.             if (! *indos) {
  69.                 C10ckEval();                    // Call Clipper function (_C10ckEval)
  70.                 TickerCount = 0;                // Reset Ticker Timer
  71.             }
  72.         }
  73.         --Busy;                                    // Decrement Busy Flag
  74.     }
  75. }
  76.  
  77.